package com.example.flinktest;

import com.example.flinktest.source.Event;
import org.apache.commons.compress.utils.Lists;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.List;

public class StreamCollection {
    public static void main(String[] args) {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        List<Event> clicks = Lists.newArrayList();
        clicks.add(new Event("Tomas", "./home", 100L));
        clicks.add(new Event("Chatgpt", "./cart", 2000L));

        DataStream<Event> stream = env.fromCollection(clicks);

        //或直接将元素列举出来
        DataStreamSource<Event> stream2 = env.fromElements(
                new Event("Jeremy", "./home", 200L),
                new Event("Aima", "./cat", 300L)
        );

        stream.print();
        stream2.print();
        try {
            env.execute();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
